package com.shallowUniverse.dmp.utils;

import com.shallowUniverse.dmp.pojo.DataBase;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;

/**
 * @author Shuai Guo
 * @version 1.0
 * @description
 * @date 2021/8/6
 */
public class DataSourceUtils {

    /**
     * description: 生成数据源 <br/>
     * author: Shuai Guo   <br/>
     * date: 2021/8/6 <br/>
     * params: [dataBase] <br/>
     * return: javax.sql.DataSource <br/>
     * version: 1.0
     */
    public static DataSource createDataSource(DataBase dataBase) {
        HikariConfig toConfiguration = new HikariConfig();
        toConfiguration.setJdbcUrl(dataBase.getUrl());
        toConfiguration.setDriverClassName(dataBase.getDriverClass());
        toConfiguration.setUsername(dataBase.getUsername());
        toConfiguration.setPassword(dataBase.getPassword());
        return new HikariDataSource(toConfiguration);
    }
}
